using System;
using System.Collections.Generic;
using System.Text;

namespace WOWEquipOptimizer.Priest
{
    class Shadow : CasterDD
    {
        public Shadow()
            : base()
        {
            m_Base = new List<Attribute>();
            m_Base.Add(new Attribute(AttributeName.Health, 2800));
            m_Base.Add(new Attribute(AttributeName.Stamina, 59));
            m_Base.Add(new Attribute(AttributeName.Mana, 2145));
            m_Base.Add(new Attribute(AttributeName.Intellect, 156));
            m_Base.Add(new Attribute(AttributeName.Spirit, 143));
            m_Base.Add(new Attribute(AttributeName.CritSpellRating, 2.2f*CritSpellRating));
            // talents
            m_Base.Add(new Attribute(AttributeName.HitSpellRating, 6 * HitSpellRating));
            m_Base.Add(new Attribute(AttributeName.CritSpellRating, 15 * CritSpellRating));
            foreach (Attribute attr in m_Base)
            {
                handleAttribute(attr);
            }
        }
        // // mana, int, spirit, spelldmg, spellcrit, spellhit, spellhaste,mp5,health
        public override float evaluateTF()
        {
            float runtime = 600;
            float mana = m_Equip[AttributeName.Mana];
            float intellect = m_Equip[AttributeName.Intellect];
            float spirit = m_Equip[AttributeName.Spirit];
            float spelldmg = m_Equip[AttributeName.SpellDamage];
            float crit = m_Equip[AttributeName.CritSpellRating] / CritSpellRating;
            float hit = m_Equip[AttributeName.HitSpellRating] / HitSpellRating;
            hit = Math.Min(83f + hit, 99);
            float haste = m_Equip[AttributeName.HasteSpellRating] / HasteSpellRating;
            float mp5 = m_Equip[AttributeName.MP5];
            float manaregic = ((spirit / 4f + 12.5f) * 0.15f) / 2 + mp5 / 5f;
            float swpdmg = 1236 + 1.2f*spelldmg;
            float swpmana = 575;
            float vtdmg = 650 + spelldmg;
            float vtmana = 425;
            float vtcount = (24 / 15f);
            float mfdmg = 528 + 0.57f * spelldmg;
            float mfmana = 230 * 0.85f;
            float mbmana = 450 * 0.85f;
            float mbdmg = 728 + (1.5f / 3.5f) * spelldmg;
            float mbcount = 0; // (24 - vtcount * 2.0f) / 6.0f;
            float swdcount = 2;
            float swdmana = 309;
            float swddmg = 618 + (1.5f / 3.5f) * spelldmg;
            float fullrotmult = 1.53f;
            float mfcount = (24 - vtcount * 2.0f - mbcount * 2.0f) / 3.0f;
            // rotation is 24s swp, vampiric embrace up, mflay otherwise
            float rotdmg = (hit / 100) * (1.1f * fullrotmult * (swpdmg + vtcount * vtdmg + mfcount * mfdmg + (swdcount * swddmg + mbcount * mbdmg) * (1 + 0.5f * crit / 100))); //cos on
            float rotmana = Math.Max(swpmana + vtmana * vtcount + mfcount * mfmana + mbcount * mbmana + swdcount * swdmana - manaregic * 24f - rotdmg * 0.05f, 1);
            float rottime = 24;
            float rotcount = Math.Min(mana / rotmana, runtime / rottime);
            float finaldps = (rotdmg * rotcount) / runtime;
            return CondFactor * finaldps;
        }
        // mana, int, spirit, spelldmg, spellcrit, spellhit, spellhaste, mp5,health
        public override void handleAttribute(Attribute attr)
        {
            switch (attr.Type)
            {
                case AttributeName.Intellect:
                    m_Equip[AttributeName.Mana] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) * 15;
                    m_Equip[AttributeName.Intellect] += attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f);
                    m_Equip[AttributeName.CritSpellRating] += (attr.Value * (HasBlessingOfKings ? 1.1f : 1.0f) / 80) * CritSpellRating;
                    break;
                case AttributeName.ShadowSpellDamage:
                case AttributeName.SpellDamage:
                    m_Equip[AttributeName.SpellDamage] += attr.Value;
                    break;
                default:
                    base.handleAttribute(attr);
                    break;
            }
        }
        public override List<Item> filterEquip(List<Item> input)
        {
            input = base.filterEquip(input);
            List<Item> retval = new List<Item>();
            ItemBlacklist.Add("Atiesh, Greatstaff of the Guardian");
            ItemBlacklist.Add("Violet Signet");
            foreach (Item item in input)
            {
                if ((item.AllowableClasses & CharacterClass.Priest) == 0) continue;
                if (item.GetType() == typeof(Weapon))
                {
                    Weapon weapon = (Weapon)item;
                    if (weapon.WeaponSlot == WeaponSlot.Ranged)
                    {
                        if (weapon.Type != WeaponType.Wand) continue;
                    }
                    if (weapon.Type == WeaponType.Axe || weapon.Type == WeaponType.Sword) continue;
                    if (weapon.TwoHand && weapon.Type != WeaponType.Staff) continue;
                }
                else if (item.GetType() == typeof(Armor))
                {
                    Armor armor = (Armor)item;
                    if ((armor.Type & ArmorProficiency.Cloth) == 0) continue;
                }
                if (SetBlacklist.Contains(item.Set.Name)) continue;
                if (ItemBlacklist.Contains(item.Name)) continue;
                retval.Add(item);
            }
            return handleWhiteList(retval);
        }
        public override bool evaluateBuild(int[] build)
        {
            if (build[2] >= 41 && build[0] >= 13)
            {
                return true;
            }
            else return false;
        }
    }
}
